#include "tcp_client.h"

namespace umtl
{
	//////////////////////////////////////////////////////////////////////////
	//

	tcp_client::tcp_client( std::string const & host, std::string const & port
		, tcp_connection::read_handler_t read_handler
		, tcp_connection::close_handler_t close_handler
	)
	{
		try
		{
			connection_ = tcp_connection::create( read_handler, close_handler );

			connection_->connect( host, port );

			connection_->read();

			connection_->run();
		}
		catch (std::exception & e)
		{
			std::cerr << e.what() << std::endl;
		}
	}

	//////////////////////////////////////////////////////////////////////////
	//

	void tcp_client::send( char const * data, size_t len )
	{
		if( data && len )
			connection_->send( data, len );
	}

	//////////////////////////////////////////////////////////////////////////
}